home *** CD-ROM | disk | FTP | other *** search
- /*EDITmOR version 1.0. © 1989, by Robert S. T. Gibson
- Reverse case ECMD:
- An external command for EDITmOR (ECMD).
-
- Reverse case is a simple routine to reverse the case of the current selection in a
- text window. Thanks to Joel McNamara for showing methods for doing so in his
- July, 1989 (Vol. 5 No. 7) article ("Extend your Favourite Editor").
-
- This is sample source code to display how one would create an ECMD for EDITmOR.
-
- Be aware that EDITmOR is subject to updates, which could cause some problems with
- some of your ECMDs. Keep your source code so you can easily make changes as to
- avoid problems. I will release sample source code, etc. with all future releases.
-
- Reverse case project file:
- --------------------------
- MacTraps
- Reverse case.c
- --------------------------
-
- Reverse case project type:
- Code resource
- File type: rsrc (if you like... rsrc is ResEdit's files type)
- Creator: RSED (if you like... RSED is ResEdit's creator)
- Custom Header: No
- Name: Reverse case (or rename it if you want)
- Type: ECMD (that's -E-DITmOR -C-o-M-man-D-)
- ID: whatever
- Attrs: 20 (purgeable)
-
- That should be about it... Copy the resource into EDITmOR's file and run the DA.
- Your command should show up in the menu.
-
- Note: If you are using Font/DA Juggler or SuitCase, you will have to close your file
- before you can edit it.
- If you are not using any such utility, you'll have to edit your System file rather
- than just the DA suitcase file.
-
- Please distribute this source to show how ECMDs are written... It's fairly simple.
- */
-
-
- int reverse(c) /*reverse the case of a character, c*/
- char c;
- {
- return((c>='A') && (c<='Z') ? (c+32) : ((c>='a') && (c<='z') ? (c-32) : c));
- /*reverse the case of the character (c) and return it*/
- } /*end reverse()*/
-
-
- pascal Boolean /*our function must be declared as pascal, for that's what it is called as*/
- main()
- {
- long len;
- Handle myHandle;
- Handle newHandle;
- long myOffset;
- long index;
-
- myHandle = NewHandle(0); /*get a new handle*/
- len = GetScrap(myHandle, 'TEXT', &myOffset); /*get length and stuff*/
-
- if (len > 0) /* must be something in the scrap before we can start converting things...*/
- {
- newHandle = NewHandle(GetHandleSize(myHandle)); /*we need a handle to use*/
-
- for (index = 0; index <= GetHandleSize(myHandle); index++)
- {
- *(((char *)(*newHandle)) + index) = reverse(*((char *)((long)(*myHandle) + index)));
- /*index through the handle and reverse each character*/
- }
-
- ZeroScrap(); /*clear the scrap*/
- PutScrap(GetHandleSize(myHandle), 'TEXT', *newHandle); /*stick our data there*/
- DisposHandle(newHandle); /*clean things up a bit*/
-
- return(true); /*must to return true to have our data pasted in*/
- /*It's for error checking, by the way, of which there is none above*/
- }
- return(false); /* nothing of type 'TEXT' in the scrap so it does not have to be pasted back in */
- } /*end main()*/
-
- /*by Robert S. T. Gibson*/
-